package com.syl.upimg.service.impl;

import com.syl.upimg.bean.BaseBean;
import com.syl.upimg.enums.ImageUploadTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author syl
 * @create 2020-04-24 21:19
 **/
@Service
public class DistributeUpload {

    @Autowired
    private AliFleece aliFleece;
    @Autowired
    private BdFleece bdFleece;
    @Autowired
    private JdFleece jdFleece;
    @Autowired
    private NetEaseFleece netEaseFleece;
    @Autowired
    private TouTiaoFleece touTiaoFleece;
    @Autowired
    private XiaoMiFleece xiaoMiFleece;
    @Autowired
    private XiTuFleece xiTuFleece;

    /**
     * 简单自动上传 上传完成后非本地就删除原文件
     * @param filePath
     * @param imageUploadTypeEnum
     * @return
     * @throws IOException
     */
    public BaseBean simpleAuto(String filePath, ImageUploadTypeEnum imageUploadTypeEnum) throws IOException {
        return (BaseBean) this.perfectAuto(filePath, imageUploadTypeEnum, ImageUploadTypeEnum.LOCAL != imageUploadTypeEnum);
    }

    /**
     * 简单自动上传
     * @param filePath
     * @param imageUploadTypeEnum
     * @param delete 是否上传完成后就删除
     * @return 返回基类
     * @throws IOException
     */
    public BaseBean simpleAuto(String filePath, ImageUploadTypeEnum imageUploadTypeEnum, boolean delete) throws IOException {
        return (BaseBean) this.perfectAuto(filePath, imageUploadTypeEnum, delete);
    }

    /**
     * 自动上传
     * @param filePath
     * @param imageUploadTypeEnum TODO 本地上传未实现
     * @param delete 是否自动删除文件
     * @return 返回完整的子类数据
     * @throws IOException
     */
    public Object perfectAuto(String filePath, ImageUploadTypeEnum imageUploadTypeEnum, boolean delete) throws IOException {
        imageUploadTypeEnum = imageUploadTypeEnum == null ? ImageUploadTypeEnum.ALI : imageUploadTypeEnum;
        switch (imageUploadTypeEnum){
            case ALI:
                return aliFleece.upload(filePath, delete);
            case BD:
                return bdFleece.upload(filePath, delete);
            case JD:
                return jdFleece.upload(filePath, delete);
            case MI:
                return xiaoMiFleece.upload(filePath, delete);
            case TT:
                return touTiaoFleece.upload(filePath, delete);
            case XT:
                return xiTuFleece.upload(filePath, delete);
            case NET_EASE:
                return netEaseFleece.upload(filePath, delete);
        }
        return aliFleece.upload(filePath, delete);
    }

}
